<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYDCONN();
$GLOBALS['MYT']=$GLOBALS['MYD'];
	$mode = 'none';
	if(isset($_GET['CCID'])){
		$GET = $GLOBALS['MYD']->db_array("SELECT ccenter_invoices.Ref, 
				ccenter_invoices.CODE, 
				ccenter_contas.Name,
				RefProvider, 
				Amount, 
				ccenter_invoices.Status, 
				TYPEPay, 
				DATE(Time) AS Time, DATE(TimeClose) AS TimeClose, DATE(TimeReceived) AS TimeReceived, DATE(TimePay) AS TimePay, DATE(TimeInvoice) AS TimeInvoice, 
				Description, PayAprove, RefOffice, 
				UserV.name AS RefUser, UserC.name AS sys_USER, 
				ProvIReference, Observations, RefCurrency, 
				DATE(TimeStart) AS TimeStart, 
				DATE(TimeEnd) AS TimeEnd, 
				RefContract, ccenter_invoices.TYPE, PayData, Ord 
			FROM ccenter_invoices 
				LEFT OUTER JOIN ccenter_contas ON ccenter_contas.CODE = ccenter_invoices.CODE
				LEFT OUTER JOIN systemoffice.main_users AS UserC ON UserC.ref = sys_USER
				LEFT OUTER JOIN systemoffice.main_users AS UserV ON UserV.ref = sys_USER
			WHERE ccenter_invoices.ref = {$_GET['CCID']}");
		$_POST['Provider'] = $GET[1]['RefProvider'];
		$_POST['Contract'] = $GET[1]['RefContract'];
		$_POST['CODE'] = $GET[1]['CODE'];
		$_POST['RefInvoice'] = $GET[1]['Ref'];
		if(!isset($GET[1]['Name'])) { $GET[1]['Name'] = ''; }
	} else {
		$DGET = $GLOBALS['MYD']->db_array("DESCRIBE ccenter_invoices");
		for($i=1;$i<=$DGET[0];$i++) {
			$GET[1][$DGET[$i]['Field']] = '';
		}
		$GET[1]['Ref'] = 0;
		$GET[1]['Amount'] = '0.00';
		$GET[1]['Name'] = '';
		$_POST['Provider'] = 0;
		$_POST['Contract'] = 0;
		$_POST['CODE'] =  0;
		$_POST['RefInvoice'] = 0;
	}
	if ($GET[1]['Status'] > 1){
	$mode = 'block';
	}
	form_pr('edtCdcInvoice','','','post');
	mn_field('hidden','ED','RefInvoice',$GET[1]['Ref'],'','','','');
	?>
	<script charset="utf-8" type="text/javascript">if(<?php echo $GET[1]['Status'];?> > 1){getElementById('pay1').style.display=block;}</script>
	<label style="position:absolute;left:15px;top:6px">Conta:</label>
	<?php 
		mn_field('button','ED','changCODE','Selecionar','','','','" style="position:absolute;top:6px;left:100px" onclick="idwindow(\'Seleccione uma conta\',\'winccaccount\',\'\',\'Modules/CentrodeCustos/obj.php?FormTree=T\',600,410)'); 
		mn_field('text','ED','CODE',$GET[1]['CODE'],'6','6','','" style="position:absolute;top:5px;left:177px'); 
		mn_field('text','ED','CODEDESCRIPTION',$GET[1]['Name'],'45','45','','" style="position:absolute;top:5px;left:237px'); ?>
	<label style="position:absolute;left:503px;top:6px">N&uacute;mero da Factura: </label>
	<?php mn_field('text','ED','ProvIReference',$GET[1]['ProvIReference'],'20','20','','" style="position:absolute;top:3px;left:600px'); ?>
	<label style="position:absolute;left:15px;top:32px">Fornecedor:</label>
	<div id="ProviderDiv" style="position:absolute;top:28px;left:100px"><?php include($GLOBALS['PAD'].'Modules/CentrodeCustos/Lib/sel_provider.php');?></div>
	<label style="position:absolute;left:503px;top:32px">Pesquisa:</label>
      <input name="SRCProvider" type="text" id="SRCProvider" size="23" style="position:absolute;top:32px;left:600px"">
	<label style="position:absolute;left:15px;top:58px">Contracto:</label> 
	<div id="ContractDiv" style="position:absolute;top:55px;left:100px"><?php include($GLOBALS['PAD'].'Modules/CentrodeCustos/Lib/sel_contract.php');?></div>
	<label style="position:absolute;left:503px;top:58px">Periodo de Facturação:</label>
     <?php mn_field('hselect','ED','RefContract',$GET[1]['RefContract'],"Semanal;Quinzenal;Mensal;Trimestral;Semestral;Anual;Bianual#1;2;3;4;5;6;7",'','','" style="position:absolute;top:58px;left:600px'); ?>
    
	<table width="100%"  border="0" cellpadding="1" cellspacing="3" style="position:absolute;left:0px;top:80px">
        <tr>
		  <td>Periodo de Facturação </td>
          <td>Data de EmissÃo</td>
          <td>Data de Recepção</td>
          <td>Limite de Pagamento</td>
          <td>Valor Liquido da Factura</td>
        </tr>
        <tr>
		  <td>De <?php mn_field('date','ED','TimeStart',$GET[1]['TimeStart'],'edtCdcInvoice','8','',''); ?> a
            <?php mn_field('date','ED','TimeEnd',$GET[1]['TimeEnd'],'edtCdcInvoice','8','',''); ?></td>
          <td><?php mn_field('date','ED','TimeInvoice',$GET[1]['TimeInvoice'],'edtCdcInvoice','8','',''); ?></td>
          <td><?php mn_field('date','ED','TimeReceived',$GET[1]['TimeReceived'],'edtCdcInvoice','8','',''); ?></td>
          <td><?php mn_field('date','ED','TimePay',$GET[1]['TimePay'],'edtCdcInvoice','8','',''); ?></td>
		  <td> (Com Impostos): &euro; <?php mn_field('text','ED','Amount',$GET[1]['Amount'],'19','10','','INPNUM');?></td>
        </tr>
    </table>
	<div id="elem_articles" style="position:absolute;left:6px;top:120px"><?php include($GLOBALS['PAD'].'Modules/CentrodeCustos/Lib/list_invoicearticles.php'); ?></div>
	<label style="position:absolute;left:370px;top:538px">Estado: </label>
	<label style="position:absolute;left:370px;top:502px">Criado por: </label>
	<label style="position:absolute;left:370px;top:520px">Validado por: </label>
	<?php 
	mn_field('text','ED','RefUser',$GET[1]['RefUser'],'','','','" style="position:absolute;left:450px;top:502px'); 
	mn_field('text','ED','SysUser',$GET[1]['sys_USER'],'','','','" style="position:absolute;left:450px;top:520px'); 
	mn_field('hselect','ED','Status',$GET[1]['Status'],"Lan&ccedilado;Pago;Arquivado;Cancelado;Pendente#1;2;3;5;8",'','','" style="position:absolute;left:450px;top:538px" onchange="
		if(this.value>1) {getElementById(\'pay1\').style.display=\'block\';} else {getElementById(\'pay1\').style.display=\'none\';}'); ?>
		
	<label style="position:absolute;left:10px;top:496px">ObservaÇ&otilde;es:</label>
	<?php 
	mn_field('textarea','ED','Description',$GET[1]['Description'],'40','4','','" style="position:absolute;height:53px;top:510px;left:10px');
	mn_field('button','ED','cdcSubmit','Guardar','','','','" style="position:absolute;width:120px;height:30px;left:850px;top:538px" onclick="
								   document.edtCdcInvoice.action=\'_response/rsproxy.php?pr=cdc_bills\';
								   subform(\'edtCdcInvoice\',\'cdcResponse\');'); ?>
	<div id="cdcResponse"></div>
	
<div id="pay1" style="display:<?php echo $mode;?>;position:absolute;top:500px;left:600px;width:200px" bgcolor="#F2F2F2">
<label style="position:absolute;top:7px;left:10px">Modo de Pagamento: </label>
<?php mn_field('select','ED','TYPEPay',$GET[1]['TYPEPay'],"SELECT Ref AS ID, name AS NAME FROM hcce_paytypes WHERE Status = 1",' ','','" style="position:absolute;top:5px;left:130px'); ?> 
<label style="position:absolute;top:27px;left:10px">NIB: </label>
<?php mn_field('text','ED','PayData',$GET[1]['PayData'],'32','32','','" style="position:absolute;top:27px;left:40px'); ?>
<label style="position:absolute;top:47px;left:10px">Data de Pagamento:</label>
<?php if($GET[1]['Status']==1){$GET[1]['TimeClose'] = date("Y-m-d");} 
	echo '<div style="position:absolute;top:45px;left:130px;width:100px">';
	mn_field('date','ED','TimeClose',$GET[1]['TimeClose'],'edtCdcInvoice','8','',''); ?></div>
</div>
</form>